package com.cx.interact.client.admin.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cx.base.apiModel.ApiModel;
import com.cx.base.autoDoc.annotations.AutoDocField;
import com.cx.base.autoDoc.annotations.AutoDocMethod;
import com.cx.base.autoDoc.annotations.AutoDocType;
import com.cx.base.controller.BaseController;
import com.cx.base.utils.StringUtil;
import com.cx.interact.client.admin.dto.consumer.ConsumerDTO;
import com.cx.interact.client.admin.service.ConsumerService;
import com.cx.interact.client.admin.utils.PropertiesUtil;

/**
 * cenxi 2017-01-12
 * */
@RequestMapping("login")
@Controller
@AutoDocType("运营平台登录")
public class LoginController extends BaseController{

	@Resource
	private ConsumerService consumerService;
	
	@RequestMapping("login")
	@ResponseBody
	@AutoDocMethod(name = "登录",  desc="",resClazz = ConsumerDTO.class)
	public ApiModel login(@AutoDocField("手机号码") String phone,@AutoDocField("密码") String password,HttpServletRequest request,HttpServletResponse response){
		//不能为空
		if(StringUtil.isNotNull(phone) && StringUtil.isNotNull(password)){
			
			ConsumerDTO dto= consumerService.queryConsumerByphoneAndPwd(phone, password);
			
			if(dto != null){
				//存session
				request.getSession().setAttribute(PropertiesUtil.getConfig().getString("LOGIN_FLAG"), dto);
				
				return buildSuccMsg(dto);
			}else{
				return buildErrorMsg(null, DATA_ERROR, "手机号码或密码有误，请确认后再输入");
			}
		}else{
			return buildErrorMsg(null, DATA_ERROR, "手机号码或密码不能为空");
		}
	}
}
